import request from '@/utils/request.ts'

// 获取电子面单账号授权地址
export const getWaybillAuthUri = () => {
  return request.get<IResponse<string>>('dd_ddgl/dou_dian/getWayBillAuthUri')
}

// 获取用户电子面单账号和网点列表
export const getUserWaybill = (params?: UserWaybillQuery) => {
  return request.get<IResponse<IUserWaybill[]>>('dd_ddgl/supply_chain/getUserWaybill', { params })
}

// 更新商家和物流商面单订购信息
export const updateWaybillAccount = (account_id: string) => {
  return request.get('dd_ddgl/supply_chain/updateWaybillAcount', { params: { acount_id: account_id } })
}

// 取消电子面单授权
export const cancelUserWaybill = (id: number) => {
  return request.post('dd_ddgl/supply_chain/canelUserWaybill', { id })
}

// 获取用户自定义电子面单模板
export const getUserWaybillTemplates = (params?: UserWaybillTemplateQuery) => {
  return request.get<PaginateResponse<IUserWaybillTemplate>>('dd_ddgl/supply_chain/getUserWaybillTemplate', { params })
}

// 获取用户快递网点
export const getUserWaybillSubscription = (pagesize = 100) => {
  return request.get<PaginateResponse<IUserWaybillSubscription>>('dd_ddgl/supply_chain/getUserWaybillSubscription', { params: { pagesize } })
}

// 获取电子面单默认模板列表
export const getStandardTemplate = (wp_code: string) => {
  return request.get<IResponse<IStandardTemplate[]>>('dd_ddgl/waybill/searchWybillTemplate', { params: { wp_code } })
}

// 获取电子面单默认模板信息
export const getCustomTemplates = (params: CustomTemplateReq) => {
  return request.get<IResponse<ICustomTemplateOuter[]>>('dd_ddgl/waybill/getWaybillTemplate', { params })
}

// 创建用户模板
export const createUserTemplate = (data: UserWaybillTemplateCreateReq) => {
  return request.post('dd_ddgl/supply_chain/createUserWaybillTemplate', data)
}

// 删除用户模板
export const deleteUserTemplate = (id: number) => {
  return request.post('dd_ddgl/supply_chain/delUserTemplate', { id })
}

// 设置默认模板
export const setDefault = (id: number) => {
  return request.post('dd_ddgl/supply_chain/defaultUserTemplate', { id })
}

export const getWayBillNumber = (data: GetWayBillNumberReq) => {
  return request.post<IResponse<IWayBillNumber>>('dd_ddgl/supply_chain/getWaybill', data)
}

// 获取自定义模板可以用字段列表
export const getCustomTemplateFields = () => {
  return request.get<IResponse<ICustomTemplateField[]>>('dd_ddgl/waybill/getWaybillTemplateField')
}

// 更新用户模板
export const updateCustomTemplate = (req: UpdateCustomTemplateReq) => {
  return request.post('dd_ddgl/supply_chain/updateUserWaybillTemplate', req)
}

// 回收电子面单号
export const recoverWaybillOrder = (data: RecoverWaybillReq) => {
  return request.post('dd_ddgl/supply_chain/cancelWaybill', data)
}

// 手动填单
export const updateTrackNumber = (data: UpdateTrackNumberReq) => {
  return request.post('dd_ddgl/supply_chain/updateTrackingNumber', data)
}

